import { createRouter, createWebHistory } from 'vue-router'
import Welcome from '../views/Login/Welcome.vue'
import Login from '../views/Login/Login.vue'
import Reg from '../views/Login/Reg.vue'
import Layout from '../views/Layout.vue'
import Home from '../views/Home/index.vue'
import Category from '@/views/Category/index.vue'
import Cart from '../views/Cart/index.vue'
import Details from '../views/Category/Details.vue'
import My from '../views/My/index.vue'
import ZhouBian from '../views/Category/zhoubian.vue'
import Dianying from '../views/Category/dianying.vue'
import manzhan from '../views/Category/manzhan.vue'
import Order from '../views/Cart/order.vue'
import Search from '../views/Home/search.vue'
import MySetup from '../views/My/MySetup.vue'
import Peripheral from '../views/Category/PeripheralDetails.vue'
import comiccondetails from '../views/Category/ComicConDetails.vue'

const router = createRouter({
  history: createWebHistory(),
  routes: [
    // 登录注册路由
      {path: '/', redirect: '/welcome'},
      {path: '/login', component: Login },
      {path: '/welcome', component: Welcome },
      {path: '/reg', component: Reg },

    {
      path: '/layout', component: Layout, redirect: '/home',
      children: [
        { path: '/home', component: Home },
        // 分类
        { path: '/category', component: Category,
        children:[
          {path:'/zhoubian',component:ZhouBian},
          {path:'/dianying',component:Dianying},
          {path:'/manzhan',component:manzhan}
        ]},
        { path: '/cart', component: Cart },
        { path: '/my', component: My }
      ]
    },
    {path:'/details',component:Details},
    {path:'/peripheral',component:Peripheral},
    {path:'/comiccondetails',component:comiccondetails,},
    {path:'/order',component:Order},
    {path:'/search',component:Search},
    {path:'/mysetup',component:MySetup}
  ]
})

// 路由拦截
// const whiteList = ['/','/login']
// router.beforeEach((to) => {
//     const isOk = whiteList.find(it=>it===to.path)
//     if(isOk){
//       return true
//     }
//     const token = localStorage.getItem('token')
//     if(token){
//       return true
//     }else{
//       return {redirect:'/login'}
//     }
// })

export default router